|
Report with groups We constructed a two-leveled report on the basis of the data from two tables in the example above. FastReport allows constructing analogous reports on the basis of one set of data, formed in a unique way. To perform this, one needs to create a query using SQL language, which would return data, arranged according to a certain condition, from both of the tables. In our case, a condition is a correspondence of the "CustNo" fields in both of the tables. An SQLquery may look as follows: select * from customer, orders The "order by" line is necessary for sorting the records in the "CustNo" field. The example below shows how the query data would be returned:
How can a multi-leveled report be constructed on the basis of this data? In FastReport there is a special band – "Group Header". A special condition is established for the band (DB field value or an expression); the band is displayed as soon as the field's value is changed. The following example illustrates this. Let us create a new project in Delphi, put the "TQuery," "TfrxReport," and "TfrxDBDataSet" components on the form. Let us set them in the following way: Query1: frxDBDataSet1: Let us open the designer and connect our data source to the report. After that, add the "Group header" and "Master data" bands to the report. Set a condition (in this case, it is "Group.CustNo" data field) in the "Group header" band editor:
Let us link data-band to the "Group" data source and place the objects in the following way (note, that the group header must be allocated above the data-band): Let us link data-band to the "Group" data source and place the objects in the following way (note, that the group header must be allocated above the data-band):
On starting, we would get a report similar to the one shown below:
As you can see, the "Group header" band is displayed only when the field, to which it is connected, changes its value. Otherwise, the data-band connected to the group is displayed. If compare this report to the master-detail report, which we constructed earlier, it seems to be obvious that order numbers are not sorted in ascending order. It can be easily corrected by changing the SQL query text: select * from customer, orders Similarly, the reports with nested group can be constructed. At the same time, the number of enclosures is unlimited in such reports. Thus, the reports with groups have some advantages over the reports of the master-detail type: - the whole report needs only one table (query); The only disadvantage is the necessity of writing queries in SQL language. However, knowledge of SQL basis is obligatory for a programmer working with databases. |
||||||||||||||||||||||||||||